//
//  ClassMPListViewController.m
//  iBaby365v2
//
//  Created by admin on 14/12/5.
//  Copyright (c) 2014年 suplus. All rights reserved.
//

#import "ClassMPListViewController.h"
#import "SPExpertContent.h"
#import "CMPListView.h"
#import "MoviePlayerViewController.h"

@interface ClassMPListViewController ()<MoviePlayerViewControllerDelegate>
@property (nonatomic, strong) MoviePlayerViewController *playerController;
@end

@implementation ClassMPListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    CMPListView *cmpv = [CMPListView headerView];
    cmpv.spexpercontent = self.spexperclass;
    self.tableView.tableHeaderView = cmpv;
}
-(NSArray *)spexpercontents
{
    if (_spexpercontents == nil) {
                _spexpercontents = [[NSArray alloc]init];
    }
    return _spexpercontents;
}
#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.spexpercontents.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ID = @"spclassmp";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if(cell == nil){
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    SPExpertContent *spcontent = self.spexpercontents[indexPath.row];
//    NSDictionary *dict = self.spexpercontents[indexPath.row];
    
    NSLog(@"spcontent.title---%@",spcontent.title);
    cell.textLabel.text = spcontent.title;
    cell.detailTextLabel.text = spcontent.createTime;
    return cell;
}
- (MoviePlayerViewController *)playerController
{
    if (!_playerController) {
        _playerController = [[MoviePlayerViewController alloc] init];
        _playerController.delegate = self;
    }
    return _playerController;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    NSIndexPath *path = [self.tableView indexPathForSelectedRow];
    SPExpertContent *spcontent = self.spexpercontents[path.row];
    NSString *urlstr = spcontent.multimediaUrl;
    self.playerController.movieURL = [NSURL URLWithString:urlstr];
    [self presentViewController:self.playerController animated:YES completion:nil];
}

- (void)moviePlayerDidFinished
{
    [self dismissViewControllerAnimated:YES completion:nil];
    self.playerController = nil;
}
//去掉无数据的cell下面的线
-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01f;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [UIView new];
}
@end
